﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using RaytracerLib.MathLib;
using RaytracerLib.Samplers;
using System.Collections.Concurrent;
using NLog;
using RaytracerLib.Postprocessing.LightCorrector;
using TomanuExtensions;
using RaytracerLib.Rays;
using System.Threading;
using RaytracerLib.Resamplers;

namespace RaytracerLib.Renderers
{
    public class BackwardRenderer : Renderer
    {
        protected override void RenderTile(Tile a_tile)
        {
            Vector2 film_size = new Vector2(Scene.ActiveCamera.Film.Width, 
                Scene.ActiveCamera.Film.Height);

            foreach (Vector2 sample in Film.Sampler.GetSamples(a_tile.Rect))
            {
                Vector2 sample_uv = sample / film_size;

                CameraRay r = Scene.ActiveCamera.CreateRay(sample_uv);
                Intersection intersection = Scene.SpatialSubdivisioner.HitTest(null, r);

                Film.Resampler.SetRayColor(sample, intersection.Color);

                if (DoShouldStop())
                    break;
            }

            TileRendered(a_tile);
        }

        public override RendererType RendererType
        {
            get
            {
                return RendererType.Backward;
            }
        }
    }
}